package com.gs.spring.core.factorybean;

import java.security.MessageDigest;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;

public class MessageDigestFactoryBean implements FactoryBean<Object>,
		InitializingBean {

	private String algorithmName = "MD5";
	
	private MessageDigest messageDigest = null; 
	
	public void afterPropertiesSet() throws Exception {
		messageDigest = MessageDigest.getInstance(algorithmName);
	}

	public Object getObject() throws Exception {
		return messageDigest.clone();
	}

	public Class<?> getObjectType() {
		return MessageDigest.class;
	}

	public boolean isSingleton() {
		return true;
	}

	public void setAlgorithmName(String algorithmName) {
		this.algorithmName = algorithmName;
	}
	
	
}
